package org.baicaixiaozhan.learn.guava.collect;

import com.google.common.base.CaseFormat;
import com.google.common.collect.Collections2;
import com.google.common.collect.Comparators;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Lists;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Random;

/**
 * DESC: {@link ComparisonChain} 示例
 *
 * @author : baicaixiaozhan
 * @since : 2020-11-13
 */
public class ComparisonChainDemo {

    public static void main(String[] args) {

        List<Integer> numberList = Lists.newArrayList();

        for (int i = 0; i < 10; i++) {
            numberList.add(new Random().nextInt(100));
        }
        System.out.println("=== before order ===");
        numberList.forEach(System.out::println);

        // 链式操作
        Collections.sort(numberList, (o1, o2) -> ComparisonChain.start()
                .compare(o1, o2)
                .result());
        System.out.println("=== after order ===");
        numberList.forEach(System.out::println);
    }
}
